cmake_minimum_required(VERSION 3.28)
project(ai_pacs)

set(CMAKE_CXX_STANDARD 20)
SET(MYSQLCONNECTORCPP_ROOT_DIR "${MYSQLCONNECTORCPP_ROOT_DIR}" CACHE PATH "start looking for this component.")
SET(ZIP_ROOT_DIR "${ZIP_ROOT_DIR}" CACHE PATH "start looking for this component.")


find_package(PkgConfig REQUIRED)
find_package(Boost REQUIRED COMPONENTS system thread)
pkg_check_modules(nlohmann_json REQUIRED nlohmann_json)
pkg_check_modules(CivetWeb REQUIRED civetweb civetweb-cpp)
find_package(yaml-cpp REQUIRED)
find_package(CURL REQUIRED)
find_package(AWSSDK REQUIRED COMPONENTS s3)
find_package(DCMTK REQUIRED CONFIG)
find_library(LibUUID_LIBRARY NAMES uuid)
find_path(LibUUID_INCLUDE_DIR NAMES uuid/uuid.h)
pkg_check_modules(PC_ZIP libzip QUIET)
find_path(ZIP_INCLUDE_DIR zip.h PATHS ${PC_ZIP_INCLUDEDIR})
find_library(ZIP_LIBRARY NAMES zip PATHS ${PC_ZIP_LIBDIR})
find_library(MYSQL_CPP_CONN_LIBRARY NAMES mysqlcppconn)
find_path(MYSQL_CPP_CONN_INCLUDE_DIR NAMES mysql_connection.h)
find_package(fmt REQUIRED)
find_package(ZLIB REQUIRED)
find_path(GMP_INCLUDE_DIR gmp.h gmpxx.h PATHS ${GMP_PREFIX}/include /usr/include /usr/local/include)
find_library(GMP_LIBRARY NAMES gmp libgmp PATHS ${GMP_PREFIX}/lib /usr/lib /usr/local/lib)
pkg_check_modules(OPENSSL REQUIRED openssl)


link_directories(
        ${CivetWeb_LIBRARY_DIRS}
        ${MYSQL_CPP_CONN_INCLUDE_DIR}
        ${YAML_CPP_LIBRARY_DIRS}
)

set(SOURCE_INCLUDE_DIR
        ${CMAKE_CURRENT_SOURCE_DIR}/constant
        ${CMAKE_CURRENT_SOURCE_DIR}/handler
        ${CMAKE_CURRENT_SOURCE_DIR}/server
        ${CMAKE_CURRENT_SOURCE_DIR}/model
        ${CMAKE_CURRENT_SOURCE_DIR}/utils
        ${CMAKE_CURRENT_SOURCE_DIR}/processor
)

aux_source_directory(src/handler HANDLER_SOURCES)
aux_source_directory(src/server SERVER_SOURCES)
aux_source_directory(src/utils UTILS_SOURCES)
aux_source_directory(src/model MODEL_SOURCES)
aux_source_directory(src/processor PROCESSOR_SOURCES)
set(SOURCE_DIR
        ${HANDLER_SOURCES}
        ${ROUTER_SOURCES}
        ${SERVER_SOURCES}
        ${MODEL_SOURCES}
        ${UTILS_SOURCES}
        ${PROCESSOR_SOURCES}
)

include_directories(
        ${Boost_INCLUDE_DIRS}
        ${NLOHMANNJSON_INCLUDE_DIRS}
        ${civetweb_INCLUDE_DIR}
        ${mysqlclient_INCLUDE_DIRS}
        ${SOURCE_INCLUDE_DIR}
        ${YAML_CPP_INCLUDE_DIRS}
        ${CURL_INCLUDE_DIRS}
        ${AWSSDK_INCLUDE_DIRS}
        ${DCMTK_INCLUDE_DIRS}
        ${ZIP_INCLUDE_DIR}
        ${LibUUID_INCLUDE_DIR}
        ${ZLIB_INCLUDE_DIR}
        ${GMP_INCLUDE_DIR}
        ${OPENSSL_INCLUDE_DIR}
)


add_executable(
        ${PROJECT_NAME}
        main.cpp
        ${SOURCE_DIR}
)


target_link_libraries(${PROJECT_NAME}
        ${Boost_LIBRARIES}
        ${CivetWeb_LIBRARIES}
        ${CivetWeb_LIBRARIES}
        ${MYSQL_CPP_CONN_LIBRARY}
        ${YAML_CPP_LIBRARIES}
        ${CURL_LIBRARIES}
        ${CURL_LIBRARIES}
        ${AWSSDK_LINK_LIBRARIES}
        ${DCMTK_LIBRARIES}
        ${ZIP_LIBRARY}
        ${LibUUID_LIBRARY}
        ${ZLIB_LIBRARY}
        ${GMP_LIBRARY}
        ${OPENSSL_LIBRARIES}

)
